<?php
namespace BeautyParlorAdmin\Controller;
use Think\Controller;
class IndexController extends Controller {
	public function _initialize() {
		
	}
	
    public function index(){
    	if (!isset($_SESSION ['beauty_parlor'])) {
    		redirect(U('login'));
    	}
    	
    	$this->display();
    }
    
    public function top() {
    	$beautyParlor = unserialize($_SESSION ['beauty_parlor']);
    	$this->assign('username', $beautyParlor ['name']);
    	$this->display();
    }
    
    public function left() {
    	$this->display();
    }
    
    public function verify() {
    	ob_clean();
    	$Verify = new \Think\Verify(array(
    		'length' => 4, 
    		'codeSet' => '0123456789',
    		'imageH' => 35,
    		'imageW' => 115,
    		'fontSize' => 16
    	));
    	$Verify->entry();
    }
    
   	public function detail() {
   		
   	}

    public function login() {
    	if (!IS_POST) {
    		if (!isset($_SESSION ['beauty_parlor'])) {
    			$redirect = I ('get.redirect');
    			if ($redirect) {
    				$this->assign('redirect', $redirect);
    			}
    			
    			$this->display();
    		} else {
    			return redirect(U('index'));
    		}
    	} else {
    		$Verify = new \Think\Verify();
    		$code = I ('post.code');
    		if (!$Verify->check($code)) {
    			$this->error('验证码有误！');
    		}
    		
    		$username = I ('post.account');
    		$password = I ('post.password');
    		
    		$adminUser = D('BeautyParlor');
    		$adminUserInfo = $adminUser->login($username, $password);
    		if (!$adminUserInfo) {
    			$this->error('账号密码错误！');
    		} else {
    			$_SESSION ['beauty_parlor'] = serialize($adminUserInfo);
    			
    			$url = U('index');
    			$redirect = I ('post.redirect');
    			
    			if ($redirect) {
    				$url = $redirect;
    			}
    			redirect($url);
    		}
    	}
    }
    
    public function logout() {
    	unset($_SESSION ['beauty_parlor']);
    	
    	redirect(U('login'));
    }
}